package cn.edu.zut.cs.Business;

import cn.edu.zut.cs.DAO.StudentDAO;
import cn.edu.zut.cs.Model.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class MarkService {
    StudentDAO studentDAO;
    @Autowired
    public void setStudentDAO(StudentDAO studentDAO) {
        this.studentDAO = studentDAO;
    }
    public void insert(Student student){
        studentDAO.insertStudent(student);
    }
    @Transactional
    public void onmark(){
        List<Student> studentList=studentDAO.queryAll();
        for(Student s :studentList){
            if(s.getMark()<60)
            {
                s.setGrade("E");
                studentDAO.modifyStudent(s);
            }
            if(s.getMark()<69&&s.getMark()>60)
            {
                s.setGrade("D");
                studentDAO.modifyStudent(s);
            }
            if(s.getMark()<79&&s.getMark()>70)
            {
                s.setGrade("C");
                studentDAO.modifyStudent(s);
            }
            if(s.getMark()<89&&s.getMark()>80)
            {
                s.setGrade("B");
                studentDAO.modifyStudent(s);
            }
            if(s.getMark()<100&&s.getMark()>90)
            {
                s.setGrade("A");
                studentDAO.modifyStudent(s);
            }
        }
    }
}
